/**
d:\flex_sdk_4.5\bin\mxmlc -static-link-runtime-shared-libraries=true ClipboardExample.as && d:\flex_sdk_4.5\bin\FlashPlayerDebugger.exe ClipboardExample.swf

 */
package
{
	import flash.external.ExternalInterface;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.events.Event;
	import flash.display.Sprite;
	import flash.desktop.Clipboard;
	import flash.desktop.ClipboardFormats;
	import flash.desktop.ClipboardTransferMode;

	public class ClipboardExample extends Sprite
	{
		private var txt:TextField = new TextField();
		public function ClipboardExample()
		{
			stage.addEventListener(MouseEvent.CLICK,clicked);
			addChild(txt);
			txt.type = "input";
		}

		private function clicked(e:Event):void
		{
			if(ExternalInterface.available){
				/*var str:String = ExternalInterface.call('function(){return window.top.location.href.toString();}');*/
				var str:String =stage.loaderInfo.parameters["str"];
				txt.text = str;
				copys(str);
				ExternalInterface.call('function(){alert("已复制到剪切板上");}');
			}
		}

		private function copys(text:String):void 
		{
			Clipboard.generalClipboard.clear();
			Clipboard.generalClipboard.setData(ClipboardFormats.TEXT_FORMAT, text);
		}

		private function pastes(e:Event=null):String
		{
			if(Clipboard.generalClipboard.hasFormat(ClipboardFormats.TEXT_FORMAT))
			{
				return String(Clipboard.generalClipboard.getData(ClipboardFormats.TEXT_FORMAT));
			} 
			else
			{
				return null;
			}
		}
	}
}



